from config import BASE_HOST
import logging

class RegLoginApi(object):

    def __init__(self,session):
        self.ses = session

    # 获取图片验证码接口
    def get_img_verify_code(self,r):

        url_img_code =BASE_HOST+"/common/public/verifycode1/{}".format(r)
        return self.ses.get(url=url_img_code)

    # 获取短信验证码接口
    def get_phone_verify_code(self,phone_v,imgcode_v,type_v="reg"):
        url_phone_code = BASE_HOST+"/member/public/sendSms"
        data ={"phone":phone_v,"imgVerifyCode":imgcode_v,"type":type_v}
        resp= self.ses.post(url=url_phone_code,data=data)
        logging.info(f"获取短信验证码返回响应体结果 : {resp.json()}")
        return resp

    # 注册接口
    def user_register(self,form_dict):
        url_reg = BASE_HOST+"/member/public/reg"
        resp= self.ses.post(url=url_reg,data=form_dict)
        print("注册返回响应体结果 : ", resp.json())
        return resp

    # 登录接口
    def user_login(self,usename_v,pwd_V):
        url_login = BASE_HOST + "/member/public/login"
        data= {"keywords":usename_v,"password":pwd_V}
        resp = self.ses.post(url=url_login,data=data)
        logging.info(f"登录返回响应体结果 : {resp.json()}")
        return resp

